package com.yanqu.road.server.cmd.activity.ghost;

import com.yanqu.road.pb.activity.GhostActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ghost.GhostModule;
import com.yanqu.road.server.manger.activity.ghost.GhostMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GHOST_EXPLORE_FROM_CROSS, desc = "处理跨服返回的探索")
public class GhostExploreFromCrossCmd extends AbstractCommand {

    private int eventType;
    private String param;
    private GhostActivityProto.TodayGhostDataMsg todayGhostDataMsg;
    private long userResetTime;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GhostActivityProto.CrossExploreRespMsg reqMsg = GhostActivityProto.CrossExploreRespMsg.parseFrom(packet.getBytes());
        ret = reqMsg.getRet();
        userResetTime = reqMsg.getUserResetTime();
        if (ret == 0) {
            eventType = reqMsg.getEventType();
            param = reqMsg.getParam();
            todayGhostDataMsg = reqMsg.getTodayGhostData();
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        GhostModule ghostModule = player.getModule(GhostModule.class);

        GhostMgr.checkUserData(player);

        ret = ghostModule.exploreFromCross(ret, eventType, param, todayGhostDataMsg, userResetTime);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            GhostActivityProto.ExploreRespMsg.Builder builder = GhostActivityProto.ExploreRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_GHOST_EXPLORE, builder);
        }
    }
}
